/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __PICTUREFORMAT_DECOMPRESSORPVR_H__
#define __PICTUREFORMAT_DECOMPRESSORPVR_H__

#include "Decompressor.h"
#include <NoCopy.h>
#include <Gluck.h>
#include <vector>

namespace liba
{
namespace pictureformat
{

typedef unsigned short int uint16_t;
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;

class DecompressorPVR : public Decompressor, private Nocopy
{
	uint32_t width, height;
	pictureformat::Format format;
	std::vector< uint8_t * > mipmaps_data;

	//decoding
	int scan_line;
	int frame;

public:
	DecompressorPVR(const void * data, int size);
	virtual ~DecompressorPVR();
	virtual int get_width(int frame)const
	{
		if(frame >= mipmaps_data.size())
			return 0;
		
		return width >> frame;
	}
	virtual int get_height(int frame)const
	{
		if(frame >= mipmaps_data.size())
			return 0;

		return height >> frame;
	}
	virtual Format get_best_format()const
	{
		return format;
	}
	virtual int get_frame_count()const
	{
		return mipmaps_data.size();
	}
	virtual void reset(Format f, int frame)
	{
		if( frame >= mipmaps_data.size() )
			THROW(Gluck( __FUNCTION__, "Frame is out of range" ));
		if( f != format )
			THROW(Gluck( __FUNCTION__, "Compressed texture: decoder must be set to the same format as the source image" ));
		
		scan_line = 0;
		this->frame = frame;
	}
	virtual void unpack_scanline(void * dst);
	virtual void skip_scanline(int count);
};

} // namespace pictureformat
} // namespace liba
using namespace liba;

#endif //__PICTUREFORMAT_DECOMPRESSORPVR_H__